
import pymysql.cursors
connect=pymysql.Connect(
    host='localhost',
    port=3306,
    user='root',
    passwd='315315',
    db='wanjia',
    charset='utf8'
)
cursor=connect.cursor()


def ui():
    user='wanjia'
    passwd='123456'
    username=input('输入用户名:')
    password = input('输入密码:')
    if username==user and password==passwd:
        print('登录成功!')
    else:
        print('用户名或密码错误')
#查询航班
def query():
    print('机票查询:')
    sql = "select*from message"
    data = ()
    cursor.execute(sql % data)
    for row in cursor.fetchall():
        print("机票编号:%d\t航班号:%d\t出发地:%s\t目的地:%s\t起飞时间:%s\t落地时间:%s\t票价:%d\t仓位类型:%s\t" % row)


#增加航班
def add():
    print('增加航班')
    sql="select*from message"
    airid=input('输入机票编号:')
    number=input('输入航班号:')
    departure=input('出发地:')
    destination=input('目的地:')
    start=input('起飞时间:')
    arrive=input('落地时间:')
    place=input('票价:')
    form=input('仓位类型:')
    sql="insert into message values('%s','%s','%s','%s','%s','%s','%s','%s')"
    data=(airid,number,departure,destination,start,arrive,place,form)
    cursor.execute(sql % data)
    connect.commit()
    print('数据插入成功')

#删除航班
def delete():
    print('删除航班')
    number=input('输入要取消的航班号:')
    sql="delete from message where number='%s'"
    data=(number)
    cursor.execute(sql%data)
    connect.commit()
    print('成功删除:')


#修改航班
def update():
    print('修改航班')
    number = input('输入要修改的机票信息:')
    sql = "update message set airid=%s,number=%s,departure=%s,destinstion=%s,start=%s,arrive=%s,place=%s,form=%s where number=%s"
    airid = input('输入机票编号:')
    number = input('输入航班号:')
    departure = input('出发地:')
    destination = input('目的地:')
    start = input('起飞时间:')
    arrive = input('落地时间:')
    place = input('票价:')
    form = input('仓位类型:')
    data=(airid,number,departure,destination,start,arrive,place,form,number)
    cursor.execute(sql % data)
    connect.commit()
    print('成功修改数据')

if __name__=="__main__":

    while(1):
       print('机票管理系统')
       print("选择操作:")
       print("11.用户登录")
       print("1.查询航班")
       print("2.增加航班")
       print("3.删除航班")
       print("4.修改航班")
       i = input('输入选项:')
       if i == "1":
        query()
       elif i == "2":
        add()
       elif i == "3":
        delete()
       elif i == "4":
        update()
       elif i=="11":
        ui()
       else:
        print('输入有误,重新输入')
